package vn.com.bookstore;

import java.io.Serializable;
import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.content.Context;
import android.os.Environment;

public class Config {
	// http://localhost:8080/RestWebServiceDemo/rest/person/sample?name=hello&age=18
	public static String IP = "http://172.21.70.115";
	public static String PORT = "8080";
	public static String URL = IP + ":" + PORT + "/ReaderBookServer/rest";
	
	public static String HEAD_IMAGE = IP + "/reader_book";

	public static final int LIMIT = 19;
	public static final int DESC_SIZE = 60;

	// get image URL
	public static String getUrlImage(String image) {
		return IP + "/reader_book/" + image;
	}

	// get cache folder
	public static String getImageCacheFolderName(Context context) {
		String filename = null;

		if (context != null) {
			if (android.os.Build.VERSION.SDK_INT > 7) {
				filename = context.getExternalCacheDir().getPath();
			} else {
				filename = Environment.getExternalStorageDirectory() + "/Android/data/" + context.getPackageName() + "/cache";
			}
		}

		return filename + "/";
	}

	// class NETOBJECT
	@SuppressWarnings("serial")
	public static class NetObject implements Serializable{
		public String url = "";
		public ArrayList<NameValuePair> param = new ArrayList<NameValuePair>();
	}

	public static class FeedBack {
		// FEEDBACK
		public static String BOOK = "/book";

		// PARAM
		public static final String USER_ID = "user_id";
		public static final String USER_NAME = "user_name";
		public static final String CONTENT = "content";

		/**
		 * POST
		 * http://172.21.70.115:8080/ReaderBookServer/rest/book?user_id=0&user_name=aloha&content=bla
		 * */
		public static NetObject getUrlFeedBack(int userId, String userName, String content) {
			NetObject obj = new NetObject();
//			obj.url = URL + BOOK;
			obj.url = IP + "/reader_book/rest"+ BOOK + "/feedback.php";
			BasicNameValuePair paramId = new BasicNameValuePair(USER_ID, userId + "");
			BasicNameValuePair paramName = new BasicNameValuePair(USER_NAME, userName + "");
			BasicNameValuePair paramContent = new BasicNameValuePair(CONTENT, content + "");
			obj.param.add(paramId);
			obj.param.add(paramName);
			obj.param.add(paramContent);
			return obj;
		}
	}

	public static class BookStore {
		// BOOK
		public static String BOOK = "/book";
		
		// PARAM
		public static final String ID = "id";
		public static final String PAGE = "page";
		public static final String LIMIT = "limit";

		/**
		 * GET
		 * http://172.21.70.115:8080/ReaderBookServer/rest/book/content?id=0&page=0&limit=19
		 * */
		// get CONTENT
		public static NetObject getUrlContent(int pageId, int page) {
			NetObject obj = new NetObject();
//			obj.url = URL + BOOK + "/content";
			obj.url = IP + "/reader_book/rest/"+ BOOK + "/content.php";
			BasicNameValuePair paramId = new BasicNameValuePair(ID, pageId + "");
			BasicNameValuePair paramPage = new BasicNameValuePair(PAGE, page + "");
			obj.param.add(paramId);
			obj.param.add(paramPage);
			return obj;
		}
		
		/**
		 * GET
		 * http://172.21.70.115:8080/ReaderBookServer/rest/book/chaps?id=0&page=0&limit=19
		 * */
		// get CHAPS
		public static NetObject getUrlListChap(int bookId, int page, int limit) {
			NetObject obj = new NetObject();
//			obj.url = URL + BOOK + "/chaps";
			obj.url = IP + "/reader_book/rest"+ BOOK + "/chaps.php";
			BasicNameValuePair paramId = new BasicNameValuePair(ID, bookId + "");
			BasicNameValuePair paramPage = new BasicNameValuePair(PAGE, page + "");
			BasicNameValuePair paramLimit = new BasicNameValuePair(LIMIT, limit + "");
			obj.param.add(paramId);
			obj.param.add(paramPage);
			obj.param.add(paramLimit);
			return obj;
		}

//		/**
//		 * GET
//		 * http://172.21.70.115:8080/ReaderBookServer/rest/book/store?id=0&page=0&limit=19
//		 * */
//		// get STORE
//		public static NetObject getUrlStore(int id, int page, int limit) {
//			NetObject obj = new NetObject();
//			obj.url = URL + BOOK + "/store";
////			obj.url = IP + "/reader_book/rest/"+ BOOK + "/store.php";
//			BasicNameValuePair paramId = new BasicNameValuePair(ID, id + "");
//			BasicNameValuePair paramPage = new BasicNameValuePair(PAGE, page + "");
//			BasicNameValuePair paramLimit = new BasicNameValuePair(LIMIT, limit + "");
//			obj.param.add(paramId);
//			obj.param.add(paramPage);
//			obj.param.add(paramLimit);
//			return obj;
//		}

		/**
		 * GET
		 * http://172.21.70.115:8080/ReaderBookServer/rest/book/books?id=0&page=0&limit=19
		 * http://172.21.70.115/reader_book/rest/book/books.php?id=1&page=1&limit=19
		 * */
		// get BOOKS
		public static NetObject getUrlListBook(int storeId, int page, int limit) {
			NetObject obj = new NetObject();
//			obj.url = URL + BOOK + "/books";
			obj.url = IP + "/reader_book/rest"+ BOOK + "/books.php";
			BasicNameValuePair paramPage = new BasicNameValuePair(PAGE, page + "");
			BasicNameValuePair paramId = new BasicNameValuePair(ID, storeId + "");
			BasicNameValuePair paramLimit = new BasicNameValuePair(LIMIT, limit + "");
			obj.param.add(paramId);
			obj.param.add(paramPage);
			obj.param.add(paramLimit);
			return obj;
		}
		
		/**
		 * GET
		 * http://172.21.70.115/reader_book/rest/book/banners?id=0&page=0&limit=19
		 * http://172.21.70.115/reader_book/rest/book/banners.php?id=0&page=0&limit=19
		 * */
		// get BOOKS
		public static NetObject getUrlListBanner(int storeId, int page, int limit) {
			NetObject obj = new NetObject();
//			obj.url = URL + BOOK + "/banners";
			obj.url = IP + "/reader_book/rest"+ BOOK + "/banners.php";
			BasicNameValuePair paramPage = new BasicNameValuePair(PAGE, page + "");
			BasicNameValuePair paramId = new BasicNameValuePair(ID, storeId + "");
			BasicNameValuePair paramLimit = new BasicNameValuePair(LIMIT, limit + "");
			obj.param.add(paramId);
			obj.param.add(paramPage);
			obj.param.add(paramLimit);
			return obj;
		}

		/**
		 * GET
		 * http://172.21.70.115:8080/ReaderBookServer/rest/book/stores?page=0&limit=19
		 * */
		// get STORES
		public static NetObject getUrlListStore(int page, int limit) {
			NetObject obj = new NetObject();
//			obj.url = URL + BOOK + "/stores";
			obj.url = IP + "/reader_book/rest"+ BOOK + "/stores.php";
			BasicNameValuePair paramPage = new BasicNameValuePair(PAGE, page + "");
			BasicNameValuePair paramLimit = new BasicNameValuePair(LIMIT, limit + "");
			obj.param.add(paramPage);
			obj.param.add(paramLimit);
			return obj;
		}
	}
}
